import axios from 'axios'
import { Message } from 'element-ui'

axios.defaults.baseURL = process.env.API_ROOT;
 
//添加拦截器,监听ajax请求状态
axios.interceptors.request.use((config) => {
	//请求发送前
	axios.defaults.headers.common['source'] = 'erp';
	return config;
}, (error) =>  {
	//请求发送前报错
	if(response.data.code != 1) {
		Message({
			type:'error',
			message:'请求数据时报错，请检查网络连接！',
		})
	}
	return Promise.reject(error);
});


axios.interceptors.response.use((response) =>  {
	//返回数据成功
	if(response.data.code != 1) {
		Message({
			type:'error',
			message:response.data.msg,
		})
	}
	return response;
}, (error) => {
	//返回数据报错
	Message({
		type:'error',
		message:'接收数据时报错，服务器错误！',
	})
	return Promise.reject(error);
});

window.imageUrl = 'http://testfile.anpxd.com:8083/'
window.axios = axios;
window.instance = axios.create();
window.defalutUrl = window.location.origin + process.env.API_ROOT;